/**
 * 
 */
package com.swim.sys.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.swim.sys.entity.IndexBanner;
import com.swim.sys.service.IndexBannerService;

/**
 * 首页bannerController
 * @author ljw
 * @version 2022-09-05
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/indexBanner")
public class IndexBannerController extends BaseController {

	@Autowired
	private IndexBannerService indexBannerService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public IndexBanner get(String id, boolean isNewRecord) {
		return indexBannerService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("sys:indexBanner:view")
	@RequestMapping(value = {"list", ""})
	public String list(IndexBanner indexBanner, Model model) {
		model.addAttribute("indexBanner", indexBanner);
		return "swim/sys/indexBannerList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<IndexBanner> listData(IndexBanner indexBanner, HttpServletRequest request, HttpServletResponse response) {
		Page<IndexBanner> page = indexBannerService.findPage(new Page<IndexBanner>(request, response), indexBanner); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("sys:indexBanner:view")
	@RequestMapping(value = "form")
	public String form(IndexBanner indexBanner, Model model) {
		model.addAttribute("indexBanner", indexBanner);
		return "swim/sys/indexBannerForm";
	}

	/**
	 * 保存首页banner
	 */
	@RequiresPermissions("sys:indexBanner:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated IndexBanner indexBanner) {
		indexBannerService.save(indexBanner);
		return renderResult(Global.TRUE, text("保存首页banner成功！"));
	}
	
	/**
	 * 删除首页banner
	 */
	@RequiresPermissions("sys:indexBanner:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(IndexBanner indexBanner) {
		indexBannerService.delete(indexBanner);
		return renderResult(Global.TRUE, text("删除首页banner成功！"));
	}
	
}